package com.ele.web;

import com.ele.pojo.Cart;
import com.ele.pojo.ResponseData;
import com.ele.service.CartService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Tag(name="购物车",description = "外卖系统的app接口文档")
public class CartController {
    @Resource
    private CartService cartService;
    @PostMapping("/addCart")
    public ResponseData<Void> addCart(@RequestBody Cart cart)
    {
        return this.cartService.addCart(cart);
    }

    @PutMapping ("/updateCart")
    public ResponseData<Void> updateCart(@RequestBody Cart cart)
    {
        return this.cartService.updateCart(cart);
    }

    /**
     * 根据登录用户的id查询购物车数据
     */
    @GetMapping("/getCartData")
    public ResponseData<Cart> getCartData(String userId){
        return this.cartService.getCartData(userId);
    }

    /**
     * 通过菜品的id批量删除购物车中的菜品数据
     */
    @GetMapping("/deleteCartByIds")
    public ResponseData<Void> deleteCartByIds(String[] ids){
        return this.cartService.deleteCartByIds(ids);
    }
    /**
     * 修改购物车数量，通过购物车的id完成
     */
    @PutMapping("/updateCartById")
    public ResponseData<Void> updateCartById(@RequestBody Cart cart){
        return this.cartService.updateCartById(cart);
    }

    /**
     * 查询购物车中被选中的数据
     */
    @GetMapping("/getCheckCart")
    public ResponseData<Cart> getCheckCart(String[] ids){
        return this.cartService.getCheckCart(ids);
    }
}